package com.futures.questionbank.main;

import android.util.DisplayMetrics;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.futures.questionbank.R;
import com.futures.questionbank.base.BaseActivity;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * author : huang
 * date   : 2020/6/17 0017 10:44
 * version: 1.0
 */
//用户协议
public class AboutAgreementActivity extends BaseActivity {

    private WebView webView;
    private TextView tv, title_textview;
    private FrameLayout fl_img;
    private int type;
    private String url;


    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.about_agreement_activity);
    }

    @Override
    protected void loadData() {
        initView();
    }

    private void initView() {
        type = getIntent().getIntExtra("type", 0);
        webView = findViewById(R.id.webview);
        tv = findViewById(R.id.tv);
        if (type == 0) {
           setTitle("用户协议");
        } else if (type == 1) {
            setTitle("隐私协议");
        }

        getAgreement();
    }

    private void getAgreement() {
        WebSettings webSettings = webView.getSettings();
        webSettings.setSupportZoom(true);
        //设置是否支持缩放
        // 设置显示缩放按钮
        webSettings.setBuiltInZoomControls(true);
        //隐藏webview缩放按钮
        webSettings.setDisplayZoomControls(false);
        //设置WebView是否允许执行JavaScript脚本，默认false，不允许
        webSettings.setJavaScriptEnabled(true);
        //设置自适应屏幕宽度 设置webview推荐使用的窗口
        webSettings.setUseWideViewPort(true);


        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int mDensity = metrics.densityDpi;
       /* if (mDensity == 240) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        } else if (mDensity == 160) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
        } else if (mDensity == 120) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
        } else if (mDensity == DisplayMetrics.DENSITY_XHIGH) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        } else if (mDensity == DisplayMetrics.DENSITY_TV) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        } else {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
        }*/
        //LayoutAlgorithm.SINGLE_C内容将自动缩放OLUMN:适应屏幕，
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        if (type == 0) {
          //  url = "https://api.zhenfujin.net/zfj/" + "system/getAgreement.php?art_id=10001";
            InputStream input= getResources().openRawResource(R.raw.helper);//xiaohuat是我的文件名，这里应该根据具体文件更改
            //  Reader reader = new InputStreamReader(input);
            InputStreamReader reader = null;   //指定格式
            BufferedReader br = null;   //指定格式
            String s = "";
            try {
                reader = new InputStreamReader(input,"GBK");
                // reader = new InputStreamReader(input);
                br = new BufferedReader(reader);
                String temp = "";
                while ((temp = br.readLine()) != null) {
                    temp += "\n";
                    s = s + temp;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            tv.setText(s);
        } else if (type == 1) {
            url = "https://api.zhenfujin.net/zfj/" + "system/getAgreement.php?art_id=10003";
            //xiaohuat是我的文件名，这里应该根据具体文件更改
            InputStream input = getResources().openRawResource(R.raw.mimi);
            //  Reader reader = new InputStreamReader(input);
            InputStreamReader reader = null;   //指定格式
            BufferedReader br = null;   //指定格式
            String s = "";
            try {
                reader = new InputStreamReader(input,"GBK");
                // reader = new InputStreamReader(input);
                br = new BufferedReader(reader);
                String temp = "";
                while ((temp = br.readLine()) != null) {
                    temp += "\n";
                    s = s + temp;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            tv.setText(s);
        }

       // webView.loadUrl(url);
      /*  Map<String, Object> params = new HashMap<>();
        Map<String, String> params2 = new HashMap<>();
        params2.put("user_id","");
        params.put("req_bd",  params2);

        HttpClient.post(this, Constants.AGREEMENT + "?art_id=10001", params, new CallBack<UserBean>() {
            @Override
            public void onSuccess(UserBean resultBean) {

            }
        });*/
    }
}
